home *** CD-ROM | disk | FTP | other *** search
/ AGA Toolkit '97 / The AGA Toolkit '97.iso / text / misc / port / string / strtonum.s < prev    next >
Encoding:
Text File  |  1996-09-07  |  512 b   |  37 lines

  1.  
  2.     XDEF    StrToNum
  3.  
  4.     XREF    StrLen
  5.  
  6. ; Returns the decimal value of the string in A0 in D0.
  7. ; Only works for values 0-99999
  8.  
  9. StrToNum:
  10.     move.l    a0,-(sp)
  11.     bsr    StrLen
  12.     move.l    (sp)+,a0
  13.     tst.l    d0
  14.     bne    .Cont
  15.     rts
  16.  
  17. .Cont:
  18.     moveq    #0,d2            ; Converted number.
  19.     moveq    #1,d3            ; 10 Multiplier.
  20.     move.l    d0,d1
  21.     subq.l    #1,d1            ; Conversion loop reg.
  22.     subq.l    #1,d0
  23.     add.l    d0,a0
  24.     moveq    #0,d0
  25.  
  26. .Loop:
  27.     move.b    (a0),d0
  28.     sub.b    #"0",d0
  29.     and.w    #$ff,d0
  30.     mulu.w    d3,d0
  31.     add.l    d0,d2
  32.     mulu.w    #10,d3
  33.     subq.l    #1,a0
  34.     dbf    d1,.Loop
  35.     move.l    d2,d0
  36.     rts
  37.